layui.use(['table', 'admin', 'ax','laydate'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var laydate = layui.laydate;

    laydate.render({
      elem: '#startTime'
    });

    laydate.render({
      elem: '#endTime'
    });

    /**
     * 采摘入库管理管理
     */
    var FruitsOrderPut = {
        tableId: "fruitsOrderPutTable"
    };

    /**
     * 初始化表格的列
     */
    FruitsOrderPut.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键id'},
            {field: 'userNumber', sort: true, title: '人员编号', style:'font-weight: 600;'},
            {field: 'goodsName', sort: true, title: '商品', style:'background-color: #fcbd71;font-weight: 600;'},
            {field: 'producetime', sort: true, title: '生产日期', style:'font-weight: 600;', totalRowText: '合计：'},
            {field: 'putWeight', sort: true, title: '入库重量', style:'font-weight: 600;', totalRow: true},
            {field: 'baozhuangWeight', sort: true, title: '包装重量', style:'font-weight: 600;', totalRow: true},
            {field: 'v1', sort: true, title: '总计', style:'font-weight: 600;',
            	templet: function(d){
            		return (d.putWeight*1+d.baozhuangWeight*1).toFixed(1)
            	}
			}
        ]];
    };

    /**
     * 点击查询按钮
     */
    FruitsOrderPut.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        queryData['startTime'] = $("#startTime").val();
        queryData['endTime'] = $("#endTime").val();
        table.reload(FruitsOrderPut.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };

    /**
     * 导出excel按钮
     */
    FruitsOrderPut.exportExcel = function () {
        var checkRows = table.checkStatus(FruitsOrderPut.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + FruitsOrderPut.tableId,
        url: Feng.ctxPath + '/fruitsOrderPut/workertask',
        page: true,
        limit: 40,
        height: "full-60",
        totalRow: true ,//开启合计行
        toolbar: '#toolbarfrom',
        cellMinWidth: 100,
        cols: FruitsOrderPut.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        FruitsOrderPut.search();
    });

    // 导出excel
    $('#btnExp').click(function () {
        FruitsOrderPut.exportExcel();
    });
});
